package com.cz.udi;

import cn.hutool.db.Db;
import cn.hutool.db.Entity;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DelBarCode {
    public static void main(String[] args) {
        try {
            Map<String,Object> params = new HashMap<>();
            params.put("material_id",1);
            params.put("warehouse_id",78);

            String group = "udi";
            String sql = "SELECT barcode_id FROM fl_barcode_second t LEFT JOIN fl_material_second t1 ON (t1.material_id = t.material_id) LEFT JOIN fl_warehouse_second t2 ON (t2.warehouse_id = t.warehouse_id) LEFT JOIN fl_material_level_second t3 ON (t3.level_id = t.level) WHERE" +
                    " (t.material_id = :material_id AND t2.warehouse_id = :warehouse_id)";
            List<Entity> list = Db.use(group).query(sql,params);
            System.out.println("条码个数:"+list.size());
            for (Entity entity : list) {
                long barCodeId = entity.getLong("barcode_id");
                int result = Db.use(group).execute("delete from fl_barcode_second where barcode_id = ?", barCodeId);
                System.out.println("删除条码结果:"+result);
            }

            String sql1 = "SELECT record_id from fl_barcode_record where warehouse_id=:warehouse_id and material_id = :material_id";
            List<Entity> list1 = Db.use(group).query(sql1,params);
            System.out.println("条码记录个数:"+list1.size());
            for (Entity entity : list1) {
                long recordId = entity.getLong("record_id");
                int result1 = Db.use(group).execute("delete from fl_barcode_record where record_id = ?", recordId);
                System.out.println("删除条码记录结果:"+result1);
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
